package com.abai.doubi.server.mq;

import com.abai.doubi.entity.pojo.Conversation;
import com.abai.doubi.server.service.IConversationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.abai.doubi.server.config.MQConfig.CONVERSATION_SAVE_QUEUE;

@Slf4j
@Component
public class ConversionConsumer {
    @Autowired
    private IConversationService conversationService;

    @RabbitListener(queues = CONVERSATION_SAVE_QUEUE)
    public void processDucument(Conversation conversation) {
        try {
            conversationService.save(conversation);
        } catch (Exception e) {
            log.error("保存会话失败：{}",conversation,e);
        }
    }
}
